/*
 * @lc app=leetcode.cn id=167 lang=javascript
 *
 * [167] 两数之和 II - 输入有序数组
 */

// @lc code=start
/**
 * @param {number[]} numbers
 * @param {number} target
 * @return {number[]}
 */
// 对撞指针
var twoSum = function(numbers, target) {
  let l = 0
  let r = numbers.length - 1
  while(l < r) {
    let ln = numbers[l]
    let rn = numbers[r]
    let total = ln + rn
    if (total === target) {
      return [l + 1, r + 1]
    } else if (total < target) {
      l++
    } else {
      r--
    }
  }
  return [-1, -1]
}
// @lc code=end
